package com.hl.sfzy.controller;

import com.hl.sfzy.entity.SearchCourse;
import com.hl.sfzy.service.SearchCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/search/courses")
public class SearchCourseController {
    @Autowired
    private SearchCourseService searchCourseService;

    @GetMapping("getCourses")
    public ResponseEntity<Map<String, Object>> getCourses(@RequestParam String query) {
        List<SearchCourse> courses = searchCourseService.searchCourses(query);

        Map<String, Object> response = new HashMap<>();
        response.put("courses", courses);
        return ResponseEntity.ok(response);
    }
}
